#include "stdafx.h"
#include "keysbox.h"

void key_sbox( const unsigned char inkeysbox[] , unsigned char outkeysbox[] )
{
	unsigned char tmp_inkeysbox ;
	unsigned char tmp_outkeysbox ;
	const unsigned char sbox[16] = { 
		0x0c , 0x05 , 0x06 , 0x0b , 
		0x09 , 0x00 , 0x0a , 0x0d ,
		0x03 , 0x0e , 0x0f , 0x08 ,
		0x04 , 0x07 , 0x01 , 0x02  } ;
		tmp_inkeysbox = (inkeysbox[3]<<3)|(inkeysbox[2]<<2)|(inkeysbox[1]<<1)|inkeysbox[0] ;
		tmp_outkeysbox = sbox[tmp_inkeysbox] ;
		for ( int i = 0 ; i<=3 ; i++ )
		{
			outkeysbox[i] = (tmp_outkeysbox >> i)&0x01 ;
		}
}